      SUBROUTINE TGLOC01(NTARGS,TARGNAME,TSEC50,KSYSNAT,KCENNAT,TARGPOS,
     *             LUERR,IERR)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE IS PART OF THE TOSS TARGET LOCATION PACKAGE, TGLOC. IT
C COMPUTES THE POSITION OF MOVING CELESTIAL TARGETS.
C
C VAR     DIM    TYPE I/O DESCRIPTION
C ---     ---    ---- --- -----------
C
C NTARGS   1      I*4  I  NUMBER OF TARGETS TO BE PROCESSED.
C                         IF ZERO OR NEGATIVE, NONE ARE PROCESSED.
C
C TARGNAME NTARGS CH*16 I NAME OF THE MOVING BODY.  VALID NAMES ARE
C                         LISTED IN TGLOC'S DESCRIPTION OF TARGNAME
C                         FOR TARGET TYPE 1.
C
C TSEC50   1      R*8   I TIME AT WHICH THE POSITION IS WANTED.  IN
C                         SECONDS SINCE 1/1/50, 0.0 HR.
C
C KSYSNAT  1      I*4   O IDENTIFIES THE NATURAL COORDINATE SYSTEM'S
C                         ORIENTATION.  IS SET TO 1 TO INDICATE THE
C                         ORIENTATION IS MEAN EARTH EQUATOR AND
C                         EQUINOX OF 1950.0
C
C KCENNAT  1      I*4   O IDENTIFIES THE NATURAL COORDINATE SYSTEM'S
C                         ORIGIN.  IS SET TO 1 TO INDICATE THE ORIGIN IS
C                         THE EARTH CENTER.
C
C TARGPOS 3,NTARGS R*8 O  TARGPOS(-,I) IS THE POSITION OF THE I'TH
C                         TARGET.  COORDS ARE IN THE GEOCENTRIC, MEAN
C                         EARTH EQUATOR AND EQUINOX OF 1950.0 SYSTEM.
C                         IN KM.
C
C LUERR    1      I*4  I  FORTRAN UNIT NUMBER FOR ERROR MESSAGES.
C                          = 0/NEGATIVE, NO MESSAGES POSSIBLE.
C
C IERR     1      I*4  O  ERROR RETURN FLAG.
C                          = 0, NO ERROR.
C                          = OTHERWISE, ERROR.
C
C***********************************************************************
C
C BY C PETRUZZO, GSFC/742, 8/85.
C        MODIFIED....
C
C***********************************************************************
C
      CHARACTER*16 TARGNAME(1)
      REAL*8 TARGPOS(3,1),POS(3)
      CHARACTER*16 NAME
C
      PARAMETER NBODIES=14
      CHARACTER*16 TARGNAMES(NBODIES)/
     *  'MERCURY', 'VENUS',   'EARTH',     ! 1,2,3
     *  'MARS',    'JUPITER', 'SATURN',    ! 4,5,6
     *  'URANUS',  'NEPTUNE', 'PLUTO',     ! 7,8,9
     *  'SUN',     '-SUN',                 ! 10,11
     *  'MOON',    '-MOON',                ! 12,13
     *  'HALLEY'/                          ! 14
C
      IBUG = 0
      LUBUG = 19
C
      IF(IBUG.NE.0) WRITE(LUBUG,2200) PAKTIM50(TSEC50),
     *     NTARGS,(I,TARGNAME(I),I=1,NTARGS)
 2200 FORMAT(/,' TGLOC01 DEBUG. TIME=',F13.6,' NTARGS=',I2//,
     *         ('  I, TARGNAME(I) = ',I3,2X,A) )
C
      IERR = 0
C
      KSYSNAT = 1     ! ORIENTATION IS MEAN OF 1950.0
      KCENNAT = 1     ! ORIGIN IS EARTH CENTER
      IF(NTARGS.LE.0) GO TO 9999
C
C GET TARGET POSITION VECTOR IN 'NATURAL' SYSTEM.
C
      DO 1000 ITARG = 1,NTARGS
      NAME = TARGNAME(ITARG)
C
C    SEARCH THE RECOGNIZABLE NAMES LOOKING FOR A MATCH WITH THE
C    CALLER'S TARGET NAME.
      KBODY = 0
      IBODY = 0
      DO WHILE (KBODY.EQ.0 .AND. IBODY.LT.NBODIES)
        IBODY = IBODY + 1
        IF(NAME.EQ.TARGNAMES(IBODY)) KBODY = IBODY
        END DO
C
      IF(KBODY.EQ.0) THEN
C      ERROR CONDITION. TARGET NAME NOT RECOGNIZED.
        IERR = 1
        TARGPOS(1,ITARG) = 'ERROR'
        TARGPOS(2,ITARG) = 'ERROR'
        TARGPOS(3,ITARG) = 'ERROR'
        IF(LUERR.GT.0) WRITE(LUERR,8001) NAME
 8001   FORMAT(' TGLOC01 ERROR. TARGET TYPE = 1. ',
     *              'BODY NAME NOT RECOGNIZED. NAME=',A)
        GO TO 1000
        END IF
C
C      GET POSITION FOR THIS TARGET.
C
      IF(KBODY.LE.9) THEN
        CALL PLANETS(TSEC50,KBODY,1,0,POS,0,KDUM)
C
      ELSE   IF(NAME.EQ.'SUN' .OR. NAME.EQ.'-SUN') THEN
        CALL SOLM50(TSEC50,POS,0)
C
      ELSE   IF(NAME.EQ.'MOON' .OR. NAME.EQ.'-MOON') THEN
        CALL LUNAM50(TSEC50,POS,0)
C
      ELSE   IF(NAME.EQ.'HALLEY') THEN
        CALL HALLEY(TSEC50,POS)
        END IF
C
      IF(NAME.EQ.'-SUN' .OR. NAME.EQ.'-MOON') THEN
        POS(1) = -POS(1)
        POS(2) = -POS(2)
        POS(3) = -POS(3)
        END IF
C
      TARGPOS(1,ITARG) = POS(1)
      TARGPOS(2,ITARG) = POS(2)
      TARGPOS(3,ITARG) = POS(3)
C
      IF(IBUG.NE.0) WRITE(LUBUG,2001)
     *       ITARG,KBODY,NAME,(TARGPOS(I,ITARG),I=1,3)
 2001 FORMAT(' TGLOC01 DEBUG. ITARG,KBODY,NAME=',2I4,2X,A/
     *       '    TARGPOS=',3G15.7)
C
 1000 CONTINUE
C
 9999 CONTINUE
C
      IF(IBUG.NE.0) WRITE(LUBUG,2002) IERR
 2002 FORMAT(/,' TGLOC01 DEBUG. AT RETURN, IERR=',I3)
      RETURN
      END
